<template>
  <a-card :bordered="false" :bodyStyle="{ padding: '0' }" :headStyle="{ padding: '0' }">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button
        v-if="!disabledButton"
        @click="handleAdd"
        type="primary"
        icon="plus"
        :disabled="isDisabledAuth('erpEmployeeFamilySocialInfo:add')">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="!disabledButton">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpEmployeeFamilySocialInfo:edit')" />
            <a-divider type="vertical" />
            <a-popconfirm title="确定删除吗?" @confirm="() => listDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpEmployeeFamilySocialInfo:delete')" />
            </a-popconfirm>
          </template>
        </span>

      </a-table>
    </div>

    <ErpEmployeeSalaryPayingUnitInfoModal ref="modalForm" @ok="handleOk"></ErpEmployeeSalaryPayingUnitInfoModal >
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpEmployeeSalaryPayingUnitInfoModal from './modules/ErpEmployeeSalaryPayingUnitInfoModal'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'

  export default {
  name: 'ErpEmployeeSalaryPayingUnitInfoList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpEmployeeSalaryPayingUnitInfoModal
    },
    props: {
      disabledButton: {
        type: Boolean,
        default: false
      },
      newData: {
        type: Array,
        default: () => []
      },
      employeeId: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
        description: '发薪单位信息页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '单位名称',
            align: 'center',
            dataIndex: 'unitName'
          },
          {
            title: '当前发薪单位',
            align: 'center',
            dataIndex: 'currFlag',
            customRender: (text, r) => {
              if (!text) {
                return ''
              } else {
                return text == '1' ? '是' : '否';
              }
            }
          },
          {
            title: '发薪开始时间',
            align: 'center',
            dataIndex: 'beginTime'
          },
          {
            title: '发薪结束时间',
            align: 'center',
            dataIndex: 'endTime'
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
            }
          }
        ],
        url: {
          list: '/api/erp/files/employee/erpEmployeeFamilySocialInfo/list',
          list0: '/api/erp/files/employee/erpEmployeeFamilySocialInfo/list?employeeId=',
          delete: '/api/erp/files/employee/erpEmployeeFamilySocialInfo/delete',
          deleteBatch: '/api/erp/files/employee/erpEmployeeFamilySocialInfo/deleteBatch',
          exportXlsUrl: '/api/erp/files/employee/erpEmployeeFamilySocialInfo/exportXls',
          exportXlsUrl0: '/api/erp/files/employee/erpEmployeeFamilySocialInfo/exportXls?employeeId=',
          importExcelUrl: 'api/erp/files/employee/erpEmployeeFamilySocialInfo/importExcel',
          importExcelUrl0: 'api/erp/files/employee/erpEmployeeFamilySocialInfo/importExcel?foreignKey=employeeId&mainId='
        },
        dictOptions: {},
        superFieldList: [],
        disableMixinCreated: true,
        colsettings: 'ErpEmployeeFamilySocialInfo:colsettings'
      }
    },
    watch: {
      $route(to, from) {
        this.url.list = this.url.list0 + this.$route.params.id;
        this.url.exportXlsUrl = this.url.exportXlsUrl0 + this.$route.params.id;
        this.url.importExcelUrl = this.url.importExcelUrl0 + this.$route.params.id;
        this.loadData();
      },
      newData(newValue) {
        this.dataSource = Object.assign([], newValue)
      }
    },
    created() {
      this.getSuperFieldList();
      // this.url.list = this.url.list0 + this.$route.params.id;
      this.url.exportXlsUrl = this.url.exportXlsUrl0 + this.$route.params.id;
      this.url.importExcelUrl = this.url.importExcelUrl0 + this.$route.params.id;
      // this.loadData();
      this.initColumns();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      listDelete(id) {
        this.dataSource.forEach((val, index) => {
          if (val.id === id) {
            this.dataSource.splice(index, 1)
          }
        })
        this.$emit('delete', this.dataSource)
      },
      handleOk(val) {
        if (val.id) {
          let index = this.dataSource.findIndex(item => item.id === val.id)
          if (index > -1) {
            this.dataSource.splice(index, 1, val)
          }
        } else {
          this.dataSource.push({ id: parseInt((Math.random() * 1000000000)).toString(), ...val })
        }
        this.$emit('ok', this.dataSource)
      },
      initDictConfig() {
      },
      handleAdd: function() {
        this.$refs.modalForm.edit({
          'employeeId': this.employeeId
        })
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'name', text: '姓名', dictCode: '' })
        fieldList.push({ type: 'string', value: 'position', text: '职务', dictCode: '' })
        fieldList.push({ type: 'string', value: 'relation', text: '与本人关系', dictCode: '' })
        fieldList.push({ type: 'date', value: 'birthday', text: '出生日期' })
        fieldList.push({ type: 'string', value: 'workUnit', text: '工作单位', dictCode: '' })
        fieldList.push({ type: 'string', value: 'politicalLandscape', text: '政治面貌', dictCode: 'political_landscape' })
        fieldList.push({ type: 'string', value: 'phone', text: '联系电话', dictCode: '' })
        fieldList.push({ type: 'int', value: 'age', text: '年龄', dictCode: '' })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
